{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Jupyter notebook扩展\n",
    "http://\n",
    "    \n",
    "## 初识地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "geo_url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "\n",
    "payload = {\n",
    "    \"key\":\"b6460f39ad29f96cd7e126f2bcba364c\",\n",
    "    \"address\":\"广东省广州市从化区\"\n",
    "}\n",
    "\n",
    "r = requests.get(url=geo_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'geocodes': [{'formatted_address': '广东省广州市从化区',\n",
       "   'country': '中国',\n",
       "   'province': '广东省',\n",
       "   'citycode': '020',\n",
       "   'city': '广州市',\n",
       "   'district': '从化区',\n",
       "   'township': [],\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'adcode': '440117',\n",
       "   'street': [],\n",
       "   'number': [],\n",
       "   'location': '113.586605,23.548852',\n",
       "   'level': '区县'}]}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "geo_url = \"https://restapi.amap.com/v3/geocode/geo?parameters\"\n",
    "\n",
    "payload = {\n",
    "    \"key\":\"b6460f39ad29f96cd7e126f2bcba364c\",\n",
    "    \"address\":\"上海市杨浦区国权北路1566号\"\n",
    "}\n",
    "\n",
    "r = requests.get(url=geo_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'count': '1',\n",
       " 'geocodes': [{'formatted_address': '上海市杨浦区国权北路1566号',\n",
       "   'country': '中国',\n",
       "   'province': '上海市',\n",
       "   'citycode': '021',\n",
       "   'city': '上海市',\n",
       "   'district': '杨浦区',\n",
       "   'township': [],\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'adcode': '310110',\n",
       "   'street': '国权北路',\n",
       "   'number': '1566号',\n",
       "   'location': '121.500963,31.338499',\n",
       "   'level': '门牌号'}]}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "城投宽庭_location = r.json()['geocodes'][0]['location']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'121.500963,31.338499'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "城投宽庭_location"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 逆地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "geo_url = \"https://restapi.amap.com/v3/geocode/regeo?parameters\"\n",
    "\n",
    "payload = {\n",
    "    \"key\":\"b6460f39ad29f96cd7e126f2bcba364c\",\n",
    "    \"location\":\"121.500963,31.338499\",\n",
    "}\n",
    "\n",
    "r = requests.get(url=geo_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'regeocode': {'addressComponent': {'city': [],\n",
       "   'province': '上海市',\n",
       "   'adcode': '310110',\n",
       "   'district': '杨浦区',\n",
       "   'towncode': '310110020000',\n",
       "   'streetNumber': {'number': '1566号',\n",
       "    'location': '121.500963,31.338499',\n",
       "    'direction': 'Center',\n",
       "    'distance': '0',\n",
       "    'street': '国权北路'},\n",
       "   'country': '中国',\n",
       "   'township': '新江湾城街道',\n",
       "   'businessAreas': [{'location': '121.497109,31.310831',\n",
       "     'name': '江湾',\n",
       "     'id': '310110'},\n",
       "    {'location': '121.482393,31.336023', 'name': '淞南', 'id': '310113'}],\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'citycode': '021'},\n",
       "  'formatted_address': '上海市杨浦区新江湾城街道国权北路1566号湾谷2期'},\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-16-f508e6866dd1>, line 7)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-16-f508e6866dd1>\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m    \"keywords\":\"广州南方学院\"，\u001b[0m\n\u001b[1;37m                       ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "geo_url = \"https://restapi.amap.com/v3/place/text?parameters\"\n",
    "\n",
    "payload = {\n",
    "    \"key\":\"b6460f39ad29f96cd7e126f2bcba364c\",\n",
    "    \"keywords\":\"广州南方学院\"，\n",
    "    \"type\":\"中餐厅\"\n",
    "}\n",
    "\n",
    "r = requests.get(url=geo_url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'regeocode': {'formatted_address': '上海市杨浦区新江湾城街道国权北路1566号湾谷2期',\n",
       "  'addressComponent': {'country': '中国',\n",
       "   'province': '上海市',\n",
       "   'city': [],\n",
       "   'citycode': '021',\n",
       "   'district': '杨浦区',\n",
       "   'adcode': '310110',\n",
       "   'township': '新江湾城街道',\n",
       "   'towncode': '310110020000',\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'streetNumber': {'street': '国权北路',\n",
       "    'number': '1566号',\n",
       "    'location': '121.500963,31.338499',\n",
       "    'direction': 'Center',\n",
       "    'distance': '0'},\n",
       "   'businessAreas': [{'location': '121.497109,31.310831',\n",
       "     'name': '江湾',\n",
       "     'id': '310110'},\n",
       "    {'location': '121.482393,31.336023', 'name': '淞南', 'id': '310113'}]}}}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
